package lin.an.food.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lin.an.food.entity.Food;
import lin.an.food.param.*;
import lin.an.food.service.FoodClicksService;
import lin.an.food.service.FoodService;
import lin.an.food.vo.FoodClicksVo;
import lin.an.food.vo.FoodDetailsVo;
import lin.an.pojo.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author zhoulinq
 * @date 2025/3/10
 */
@RestController
@RequestMapping("/delicious/food")
public class FoodController {

    @Autowired
    private FoodService foodService;
    
    @Autowired
    private FoodClicksService foodClicksService;

    /**
     *  分页查询美食
     */
    @PostMapping("/page")
    public CommonResult<Page<Food>> page(@RequestBody FoodPageParam foodPageParam){
        return CommonResult.data(foodService.page(foodPageParam));
    }

    /**
     * 模糊查询
     * @param
     */
    @PostMapping("/like")
    public CommonResult<List<Food>> like(@RequestBody FoodLikeParam foodLikeParam){
        return CommonResult.data(foodService.like(foodLikeParam));
    }

    /**
    *   美食图片上传
    */
    @PostMapping("/upload")
    public CommonResult<String> upload(@RequestPart("file") MultipartFile file){
        return CommonResult.data(foodService.uploadReturnUrl(file));
    }
    /**
     * 添加美食
     */
    @PostMapping("/add")
    public CommonResult<String> add(@RequestBody FoodAddParam foodAddParam) {
        foodService.add(foodAddParam);
        return CommonResult.ok();
    }

    /**
     * 删除美食(批量)
     */
    @PostMapping("/delete")
    public CommonResult<String> delete(@RequestBody List<FoodDeleteParam> foodDeleteParamList) {
        foodService.delete(foodDeleteParamList);
        return CommonResult.ok();
    }

    /**
     * 修改美食信息
     */
    @PostMapping("/edit")
    public CommonResult<String> edit(@RequestBody FoodEditParam foodEditParam) {
        foodService.edit(foodEditParam);
        return CommonResult.ok();
    }
    /**
     * 美食推荐
     */
    @GetMapping("/recommend")
    public CommonResult<List<Food>> recommend(@RequestParam Integer userId){
        return CommonResult.data(foodService.recommend(userId));
    }

    /**
     * 获取美食详情
     */
    @PostMapping("/detail")
    public CommonResult<FoodDetailsVo> details(@RequestBody FoodDetailParam foodDetailParam){
        return CommonResult.data(foodService.detail(foodDetailParam));
    }
    /**
     * 获取炒菜分类美食数据
     */
    @GetMapping("/chaocai")
    public CommonResult<Page<Food>> chaoCaiPage(FoodPageParam foodPageParam){
        return CommonResult.data(foodService.chaoCaiPage(foodPageParam));
    }
    /**
     * 获取炖菜分类美食数据
     */
    @GetMapping("/duncai")
    public CommonResult<Page<Food>> dunCaiPage(FoodPageParam foodPageParam){
        return CommonResult.data(foodService.dunCaiPage(foodPageParam));
    }
    /**
     * 获取烧烤分类美食数据
     */
    @GetMapping("/shaokao")
    public CommonResult<Page<Food>> shaoKaoPage(FoodPageParam foodPageParam){
        return CommonResult.data(foodService.shaoKaoPage(foodPageParam));
    }
    /**
     * 获取蒸菜分类美食数据
     */
    @GetMapping("/zhengcai")
    public CommonResult<Page<Food>> zhengCaiPage(FoodPageParam foodPageParam){
        return CommonResult.data(foodService.zhengCaiPage(foodPageParam));
    }
    /**
     * 获取主食分类美食数据
     */
    @GetMapping("/zhushi")
    public CommonResult<Page<Food>> zhuShiPage(FoodPageParam foodPageParam){
        return CommonResult.data(foodService.zhuShiPage(foodPageParam));
    }
    /**
     * 获取小吃分类美食数据
     */
    @GetMapping("/xiaochi")
    public CommonResult<Page<Food>> xiaoChiPage(FoodPageParam foodPageParam){
        return CommonResult.data(foodService.xiaoChiPage(foodPageParam));
    }
    /**
     * 获取总美食数
     */
    @GetMapping("/amount")
    public CommonResult<Long> amount(){
        return CommonResult.data(foodService.amount());
    }
    
    /**
     * 获取点击数最多的前10条美食数据
     */
    @GetMapping("/top-clicks")
    public CommonResult<List<FoodClicksVo>> getTopClicks(){
        return CommonResult.data(foodClicksService.getTopClicks());
    }
}
